// 引入Sequelize模块
const Sequelize = require('sequelize');

// 引入数据库实例
const db = require('../db');

const commonToken = db.define("commonToken", {
    objectId: {
        type: Sequelize.STRING(20),
        allowNull: false,
        unique: true,
        primaryKey: true
    },

    token: {
        type: Sequelize.STRING(300),
    },

    expires_time: {
        type: Sequelize.BIGINT,
        defaultValue: 0,
    },

    type: {
        type: Sequelize.STRING(20),
    },

    createdAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('createdAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

    updatedAt: {
        type: Sequelize.DATE,
        get() {
            const rawValue = this.getDataValue('updatedAt');
            return dateFormat(rawValue, 'yyyy-mm-dd HH:MM:ss');
        }
    },

}, {
    // 是否支持驼峰
    underscored: false,
    // MySQL数据库表名
    tableName: "commonToken",
});

/*(async () => {
    commonToken.sync({
        alter: true
    });

    console.log("token同步成功")
})();*/

module.exports = {
    commonToken
};
